Skip to content

MkSpeechBubble

Show source on GitHub

Node for showing a css-based speech bubble.

Example: Regular

Jinja

{{ "some text" | MkSpeechBubble }}

Python

MkSpeechBubble('some text')

some text

<div class="speech bottom" markdown="1">
some text
</div>
<div class="speech bottom">
<p>some text</p>
</div>
MkSpeechBubble
╰── MkText('some text')

Example: No arrow

Jinja

{{ "some text" | MkSpeechBubble(arrow=None) }}

Python

MkSpeechBubble('some text', arrow=None)

some text

<div class="speech" markdown="1">
some text
</div>
<div class="speech">
<p>some text</p>
</div>
MkSpeechBubble
╰── MkText('some text')

Bases: MkContainer

Name Children Inherits
MkContainer
mknodes.basenodes.mkcontainer
A node containing other MkNodes.
graph TD
  94721306003376["mkspeechbubble.MkSpeechBubble"]
  94721311697232["mkcontainer.MkContainer"]
  94721308848336["mknode.MkNode"]
  94721311766592["node.Node"]
  140564252373184["builtins.object"]
  94721311697232 --> 94721306003376
  94721308848336 --> 94721311697232
  94721311766592 --> 94721308848336
  140564252373184 --> 94721311766592
/home/runner/work/mknodes/mknodes/mknodes/basenodes/mkspeechbubble/metadata.toml
[metadata]
icon = "mdi:chat"
name = "MkSpeechBubble"

[[resources.css]]
filename = "speechbubble.css"

[examples.regular]
title = "Regular"
jinja = """
{{ "some text" | MkSpeechBubble }}
"""

[examples.no_arrow]
title = "No arrow"
jinja = """
{{ "some text" | MkSpeechBubble(arrow=None) }}
"""

[output.markdown]
template = """
<div class="speech{{ node.arrow | add(prefix=' ') }}" markdown="1">
{{node.items  | join(node.block_separator) }}
</div>
"""
mknodes.basenodes.mkspeechbubble.MkSpeechBubble
class MkSpeechBubble(mkcontainer.MkContainer):
    """Node for showing a css-based speech bubble."""

    ICON = "material/chat"
    CSS = [resources.CSSFile("speechbubble.css")]

    def __init__(
        self,
        content: str | mknode.MkNode | list | None = None,
        *,
        arrow: Literal["top", "bottom", "left", "right"] | None = "bottom",
        **kwargs,
    ):
        self.arrow = arrow
        super().__init__(content=content or [], **kwargs)

    def get_element(self) -> xml.Div:
        klass = f"speech {self.arrow}" if self.arrow else "speech"
        root = xml.Div(klass, markdown=True)
        root.text = "\n" + super()._to_markdown() + "\n"
        return root

    def _to_markdown(self) -> str:
        return self.get_element().to_string()